package com.tony.springbootthymeleaf.controller;

import com.tony.springbootthymeleaf.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.UUID;

/**
 * 用户相关功能控制器
 *
 * @author Xuxiaoyu
 * created in 2024/12/3 15:48:05
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

    @RequestMapping("/toUserList")
    public String toUserList(Model model) {
        ArrayList<User> users = new ArrayList<>();
        users.add(new User(UUID.randomUUID().toString(), "zhao", "赵", "13000000000"));
        users.add(new User(UUID.randomUUID().toString(), "qian", "钱", "13000000001"));
        users.add(new User(UUID.randomUUID().toString(), "sun", "孙", "13000000002"));
        users.add(new User(UUID.randomUUID().toString(), "li", "李", "13000000003"));
        users.add(new User(UUID.randomUUID().toString(), "zhou", "周", "13000000004"));
        users.add(new User(UUID.randomUUID().toString(), "wu", "吴", "13000000005"));
        users.add(new User(UUID.randomUUID().toString(), "zheng", "郑", "13000000006"));
        users.add(new User(UUID.randomUUID().toString(), "wang", "王", "13000000007"));
        model.addAttribute("users", users);
        return "userList";
    }

    @RequestMapping("/getUser")
    public String getUser(Model model) {
        model.addAttribute("user", new User(UUID.randomUUID().toString(), "nico", "吴江德", "13965899033"));
        return "user";
    }

    @RequestMapping("/toFragment")
    public String toFragment() {
        return "layout";
    }
}
